<?php
namespace App\Controllers;
use \interop\Container\ContainerInterface as ContainerInterface;
use App\Models\UserModel;
use App\Models\OperaModel;
use pdo;
class OrderController extends BaseController{
	public function orderfinished($request,$respone,$args){
		$user=new UserModel();
		$oper=neW OperaModel();
		$postTime=$request->getParam('postTime');
		if($postTime==""){
			if($user->orderfinished()){
			$result=json_encode($user->orderfinished());
		    }
		    else{
			   $result="a";
		    }  
		}
		else{
				$result=json_encode($oper->orderfinished($postTime));
		}
		
		return $result;
	}
	public function orderunfinish($request,$respone,$args){
		$user=new UserModel();
		$oper=neW OperaModel();
		$postTime=$request->getParam('postTime');
		if($postTime==""){
			if($user->orderunfinish()){
			$result=json_encode($user->orderunfinish());
		    }
		    else{
			   $result="a";
		    }  
		}
		else{
				$result=json_encode($oper->orderunfinish($postTime));
		}
		
		return $result;
	}
	public function ordercount(){
		$user=new UserModel();
		$ret=$user->ordercount();
		if($user->ordercount()){
			$result=count($ret);
		}
		else{
			$result="a";
		}
		return "$result";
	}
	 public function distribcount(){
	 	$user=new UserModel();
	 	$ret=$user->distribcount();
	 	if($user->distribcount()){
	 		$result=count($ret);
	 	}
	 	else{
	 		$result="a";
	 	}
	 	return "$result";
	 }
	 public function announcecount(){
	 	$user=new UserModel();
	 	$ret=$user->announcecount();
	 	if($user->announcecount()){
	 		$result=count($ret);
	 	}
	 	else{
	 		$result="a";
	 	}
	 	return "$result";
	 }
	 public function ordermsg($request,$respone,$args){
	 	$oper=new OperaModel();
	 	$id=$request->getParam('id');
	 	if($oper->ordermsg($id)){
     		$ret=json_encode($oper->ordermsg($id));
     		$data=array('message'=>"$ret",'code'=>0);
     	}else{
     		$data=array('message'=>'用户操作失败','code'=>101);
     	}
     	return $respone->withJSON($data);;
	 }
	 public function orderedit($request,$respone,$args){
	 	$oper=new OperaModel();
	 	$id=$request->getParam('id');
	 	$orderman=$request->getParam('orderman');
	 	$ordernumber=$request->getParam('ordernumber');
	 	$ordercontxt=$request->getParam('ordercontxt');
	 	$ordertime=$request->getParam('ordertime');
	 	$orderdate=$request->getParam('orderdate');
	 	$state=$request->getParam('state');
	 	$ret=json_encode($oper->orderedit($id,$orderman,$ordernumber,$ordercontxt,$ordertime,$orderdate,$state));
	 	if($ret){
     		$data=array('massage'=>'用户操作成功','code'=>0);
	 	}
	 	else{
     		$data=array('massage'=>'用户操作失败','code'=>101);
	 	}
     	return $respone->withJSON($data);;
	 }
	 public function orderdel($request,$respone,$args){
	 	$user=new UserModel();
     	$ids=$request->getParam('id');
     	if(is_array($ids)){
     		$id= implode(",",$ids);
     		if($user->orderdels($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	else{
     		$id=$ids;
     		if($user->orderdel($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	return $respone->withJSON($data);
	 }
	}
?>